package com.ruoyi.od_organizer.service.impl;

import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.ruoyi.od.service.impl.OdUserArticleServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.od_organizer.mapper.OdActivityScoreMapper;
import com.ruoyi.od_organizer.domain.OdActivityScore;
import com.ruoyi.od_organizer.service.IOdActivityScoreService;

/**
 * 评价查看Service业务层处理
 * 
 * @author 榛子
 * @date 2023-06-30
 */
@Service
public class OdActivityScoreServiceImpl implements IOdActivityScoreService 
{
    @Autowired
    private OdActivityScoreMapper odActivityScoreMapper;

    /**
     * 查询评价查看
     * 
     * @param id 评价查看主键
     * @return 评价查看
     */
    @Override
    public OdActivityScore selectOdActivityScoreById(Long id)
    {
        return odActivityScoreMapper.selectOdActivityScoreById(id);
    }

    /**
     * 查询评价查看列表
     * 
     * @param odActivityScore 评价查看
     * @return 评价查看
     */
    @Override
    public List<OdActivityScore> selectOdActivityScoreList(OdActivityScore odActivityScore)
    {
        return odActivityScoreMapper.selectOdActivityScoreList(odActivityScore);
    }

    /**
     * 新增评价查看
     * 
     * @param odActivityScore 评价查看
     * @return 结果
     */
    @Override
    public int insertOdActivityScore(OdActivityScore odActivityScore)
    {
        String contentWithoutTags = OdUserArticleServiceImpl.HTMLUtils.removeTags(odActivityScore.getContent());
        odActivityScore.setContent(contentWithoutTags);
        return odActivityScoreMapper.insertOdActivityScore(odActivityScore);
    }

    /**
     * 修改评价查看
     * 
     * @param odActivityScore 评价查看
     * @return 结果
     */
    @Override
    public int updateOdActivityScore(OdActivityScore odActivityScore)
    {
        return odActivityScoreMapper.updateOdActivityScore(odActivityScore);
    }

    /**
     * 批量删除评价查看
     * 
     * @param ids 需要删除的评价查看主键
     * @return 结果
     */
    @Override
    public int deleteOdActivityScoreByIds(Long[] ids)
    {
        return odActivityScoreMapper.deleteOdActivityScoreByIds(ids);
    }

    /**
     * 删除评价查看信息
     * 
     * @param id 评价查看主键
     * @return 结果
     */
    @Override
    public int deleteOdActivityScoreById(Long id)
    {
        return odActivityScoreMapper.deleteOdActivityScoreById(id);
    }
    public class HTMLUtils {
        public static String removeTags(String html) {
            // 定义 HTML 标签的正则表达式
            String pattern = "<[^>]*>";
            // 创建 Pattern 对象
            Pattern p = Pattern.compile(pattern);
            // 创建 Matcher 对象
            Matcher m = p.matcher(html);
            // 使用 replaceAll() 方法替换所有匹配的标签为空字符串
            String result = m.replaceAll("");
            return result;
        }
    }
}
